<?php
class MilestoneversionTable extends Doctrine_Table
{
	public function getMilestoneVersionsInfo()
  {
    $resourceId = sfContext::getInstance()->getUser()->getGuardUser()->getResource()->getResourceid();
	$selectedProject = sfContext::getInstance()->getUser()->getAttribute('selectedProject');

   $versionsInfo = Doctrine_Query::create()->select('m.name,m.startdate,m.enddate,m.estimatedcost AS cost,count(Distinct t.taskid) as task_count, count(Distinct t.resourceid) as resource_count, m.version as versioncode')
       	    ->from('milestone m')
		    ->leftJoin('m.Milestoneversion mv')
     		->leftJoin('m.Task t')            
            ->where('m.createdby = ?', $resourceId)
			->andwhere('m.projectid = ?', $selectedProject->getProjectid())
		    ->groupBy('t.taskid')
         
            ->execute();	
	return $versionsInfo;	
  }
  public function getMaxMilestoneVersions()
  {

	$selectedProject = sfContext::getInstance()->getUser()->getAttribute('selectedProject');
   $versions = Doctrine_Query::create()->select('mv.versioncode')
    	    ->from('Milestoneversion mv')
            ->where('mv.projectid = ?', $selectedProject->getProjectid())
			->orderBy('mv.versioncode desc')
            ->execute();	
	return $versions[0];	
  }
}